home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbfaqr01.zip / CIRCLER.DOC < prev    next >
Text File  |  1992-07-19  |  3KB  |  110 lines

  1. ===========================================================================
  2.  BBS: PC Connect
  3. Date: 07-16-92 (00:10)             Number: 13498
  4. From: PETER FICHERA                Refer#: NONE
  5.   To: ROBERT HELMBOLD               Recvd: NO  
  6. Subj: CIRCLE                         Conf: (11) R-QBasic
  7. ---------------------------------------------------------------------------
  8. ' RH>JP>RH>JP>EL>        Does anybody know how to determine the largest squ
  9. ' RH>JP>  >JP>EL>box inside
  10. '                    ^^^^^^
  11.  
  12. ' RH>JP>  >JP>EL>a circle created with QB's CIRCLE with a known radius?  So
  13. ' RH>JP>  >JP>the coordinates of the box are (x-r,y), (x,y+r), (x+r,y) and
  14. ' RH>JP>  >JP>(x,y-r).  Draw lines connecting the four corners.
  15. ' RH>JP>  >~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. '              ^^^^^
  17. '  This gives a DIAMOND.
  18.  
  19. ' RH>JP>  >Careful. That will give the *smallest* square *outside* the circ
  20. ' RH>JP>
  21. ' RH>JP>Not true.
  22. ' RH>JP>Try it.
  23. ' RH>~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. ' RH>You are correct. I was too hasty there.
  25.  
  26. ' Wha' yo talkin' 'bout?  Robert is correct:  I hereby submit a small
  27. ' program, originally in AmigaBASIC but ported to the IBM--on a CGA Lo-Res
  28. ' screen, no less--that demonstrates just the problem--and the solution.
  29.  
  30. ' You see, in most forms of Microsoft BASIC, CIRCLE compensates for the
  31. ' inconvenience of odd shaped pixels with a default aspect ratio:  On the
  32. ' Mac, and in VGA modes with square pixels, it's 1; on a high-res CGA
  33. ' screen, it's .44.  So, you have to compensate for this somehow, and the
  34. ' compensations are imperfect--hence the fudge-factors in the following
  35. ' code:
  36.  
  37. ' ----------------------------- CUT HERE -------------------------------
  38. Machine$ = "IBM"
  39.  
  40. ' Does anybody know how to determine the largest squrare box inside
  41. ' a circle created with QB's CIRCLE with a known radius?
  42.  
  43.  
  44. 'the coordinates of the box are (x-r,y), (x,y+r), (x+r,y) and
  45. '(x,y-r).  Draw lines connecting the four corners.
  46.  
  47.  
  48. IF Machine$ = "IBM" THEN
  49.   SCREEN 1
  50. END IF
  51.  
  52. 'for the greatest Circumscribed DIAMOND, instead of
  53.  
  54. sq2=SQR(2)/2
  55.  
  56. ' use
  57. ' sq2 = SQR(2)
  58.  
  59.  
  60.  
  61. x = 160          ' Center the circle on screen
  62. y = 100
  63. r = 50           ' Circle is 50 pixels in nominal radius
  64. ar = 1           ' Actual Aspect Ratio to be shown
  65. sar = .88        ' Screen Aspect ratio
  66. nar = ar * sar   ' Net Aspect Ratio
  67. rr = r * nar - 1 ' y value of radius. ("-1") is fudge-factor!
  68.                  ' NOTE:  For general use, you'll have to be a LOT
  69.                  ' cleverer than this if you want to use ellipses...
  70.  
  71. CIRCLE (x, y), r, 1 ' make the call
  72.  
  73. ' Corners of outside box:
  74. xb = x - r
  75. xf = x + r
  76. yb = y - rr
  77. yf = y + rr
  78.  
  79. 'Box OUTSIDE the CIRCLE
  80. LINE (xb, yb)-(xf, yf), 2, B
  81.  
  82. irx = INT(r * sq2) - 1' 1/2 the width of inside box
  83.                     ' with fudge-factor
  84. iry = irx * nar     ' 1/2 the hight of box--acct'ing for AR.
  85.  
  86. ' Corners of inside box
  87. xbi = x - irx
  88. xfi = x + irx
  89. ybi = y - iry
  90. yfi = y + iry
  91.  
  92. 'Call it!
  93. LINE (xbi, ybi)-(xfi, yfi), 3, B
  94.  
  95.  
  96. '------------------------------CUT HERE-------------------------
  97.  
  98. ' Of course, if you want a DIAMOND, then use
  99.  
  100. LINE (x,yb)-(xb,y)
  101. LINE (xb,y)-(x,yf)
  102. LINE (x,yf)-(xf,y)
  103. LINE (xf,y)-(x,yb)
  104.  
  105.  
  106. ' [:^)>
  107.  
  108. PCRelay:LOCKSOFT -> #981 RelayNet (tm)
  109. 4.11                Locksoft bbs (714)766-8219 Hemet CA/HST 24hrs
  110.